package com.sls.web.manager.action.recharge;

import javax.annotation.Resource;

import com.sls.web.manager.action.SuperAction;
import com.sls.web.manager.common.Constants;
import com.sls.web.manager.page.Pagination;
import com.sls.web.manager.recharge.pojo.Dict;
import com.sls.web.manager.recharge.querybean.DictQuery;
import com.sls.web.manager.recharge.service.DictService;

public class DictAction extends SuperAction {

	private static final long serialVersionUID = 4481392243325410196L;
	@Resource(name = "dictService")
	private DictService dictService;
	private Pagination<Dict> page;
	private DictQuery dictQuery;
	private Dict dict;

	public String list() {
		try {
			if (dictQuery == null) {
				dictQuery = new DictQuery();
				dictQuery.setCurrentPage(Constants.INIT_CURRENTPAGE);
				dictQuery.setPageSize(Constants.INIT_PAGESIZE);
			}
			page = dictService.findPage(dictQuery, getCurrentOperator());
		} catch (Exception e) {
			addActionError(e.getMessage());
		}
		return "list";
	}

	public String add() {
		if (dict == null) {
			return "edit";
		}
		try {
			dictService.saveDict(dict, getCurrentOperator());
		} catch (Exception e) {
			addActionError(e.getMessage());
		}
		return list();
	}

	public String update() {
		try {
			if (dict.getId() != null && dict.getCode() == null) {
				dict = dictService.findDictById(dict.getId(),
						getCurrentOperator());
				return "edit";
			} else {
				dictService.updateDict(dict, getCurrentOperator());
			}
		} catch (Exception e) {
			addActionError(e.getMessage());
		}
		return list();
	}

	public String delete() {
		try {
			dictService.deleteDict(dict, getCurrentOperator());
		} catch (Exception e) {
			addActionError(e.getMessage());
		}
		return list();
	}

	public Pagination<Dict> getPage() {
		return page;
	}

	public void setPage(Pagination<Dict> page) {
		this.page = page;
	}

	public DictQuery getDictQuery() {
		return dictQuery;
	}

	public void setDictQuery(DictQuery dictQuery) {
		this.dictQuery = dictQuery;
	}

	public Dict getDict() {
		return dict;
	}

	public void setDict(Dict dict) {
		this.dict = dict;
	}

}
